<template>
	<view class="admin-manage">
		<uni-list :border="true">
			<uni-swipe-action>
			    <uni-swipe-action-item v-for="(item,index) in adminList" :key="item.id" :right-options="options"  @click="bindClick(item.id,$event)" @change="swipeChange($event, index)">
					<uni-list-chat :avatar-circle="true" :title="item.username" :avatar="item.avatar" :note="item.discription" :time="item.star" ></uni-list-chat>
			    </uni-swipe-action-item>
			</uni-swipe-action>
		</uni-list>
	</view>
</template>

<script>
	import { GetAdminList, DelAdmin } from '../../api/index.js'
	export default {
		data() {
			return {
				avatarList: [{
								url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
							}, {
								url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
							}, {
								url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
							}],
							  options:[
								  {
								      text: '编辑',
								      style: {
								          backgroundColor: '#007aff'
								      }
								  },
							        {
							            text: '取消',
							            style: {
							                backgroundColor: '#007a00'
							            }
							        }, {
							            text: '删除',
							            style: {
							                backgroundColor: '#dd524d'
							            }
							        }
							      ],
								  adminList:[]
			};
		},
		onLoad() {
			this.getAdminList(0)
		},
		methods:{
			async getAdminList(type){
				const { data:res } =await GetAdminList(type)
				console.log(res,'adminlist')
				if(res.status==0){
					this.adminList = res.data
				}
			},
			swipeChange(e,index){
			      console.log('当前状态：'+ e +'，下标：' + index)
			},
			bindClick(id,e){
				console.log(id,e,'ee')
				if(e.index==0){
					uni.navigateTo({
						url:'/subPackageAdmin/EditInfo/EditInfo?id='+id
					})
				}
				if(e.index==1){
					
				}
				if(e.index==2){
					return this.delAdmin(id,0)
				}
			},
			async delAdmin(id,type){
				const { data:res } = await DelAdmin(id,type)
				console.log(res,'del',this)
				if(res.status==0){
					let that = this
					uni.showModal({
						title:res.message,
						icon:'success',
						success() {
							let index = that.adminList.findIndex(item=>item.id == id)
							that.adminList.splice(index,1)
						}
					})
					
				}
			}
		}
	}
</script>

<style lang="scss">

</style>
